package operation;

import book.BookList;
import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要删除书的书名");
        String name=scanner.nextLine();
        int size = bookList.getUseSize();
        int i=0;
        for (i = 0; i < size; i++) {
            if(bookList.getbook(i).getName().equals(name)){
                break;
            }
        }
        if(i==size){
            System.out.println("你要删除的书不存在");
            return;
        }
        int j=0;
        for ( j = i; j <size-1; j++) {
            bookList.setbook(j,bookList.getbook(j+1));
        }
        bookList.setbook(j,null);
        bookList.setUseSize(size-1);
        System.out.println("删除成功");
    }
}
